package com.health.mapp.impl;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.health.db.model.UserLIST;
import com.health.db.service.user.IUserLISTService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.ModifyUserNameReq;
import com.health.mapp.bean.ModifyUserNameResp;
import com.health.mapp.utils.Response;

public class ModifyUserNameImpl implements ActionInterface{
	
	
	private static Logger logger = Logger.getLogger(ModifyUserNameImpl.class);

	private IUserLISTService userLISTService  ;
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		// TODO Auto-generated method stub
		
		//do it bobo
		ModifyUserNameReq req=(ModifyUserNameReq) reqBean;
		ModifyUserNameResp _resp=new ModifyUserNameResp();
		String userId=req.getUserId();
		String userName=req.getUserName();
		String iconUrl=req.getIconUrl();
		
		if (null==userName||userName.equals("")){
			_resp.setErrorCode(-1);
			_resp.setErrorMsg("昵称不能为空");
		}else {
			UserLIST userList=userLISTService.selectByUserId(Long.valueOf(userId));
			if (null==userList) {
				_resp.setErrorCode(-1);
				_resp.setErrorMsg("查询不到相关用户信息");
			}else
			{
				userList.setUserName(userName);
				userList.setUpdateDate(new Date());
				
				if (StringUtils.isNoneBlank(iconUrl)) {
					userList.setIconUrl(iconUrl);
				}
				
				int result=userLISTService.updateByPrimaryKey(userList);
				logger.info("更新用户昵称结果是："+result);
				if (result>0) {
					_resp.setErrorCode(0);
					_resp.setErrorMsg("更新用户昵称成功");
				}else {
					_resp.setErrorCode(-1);
					_resp.setErrorMsg("更新用户昵称失败");
				}
			}
		}
		
		return _resp;
	}
	public IUserLISTService getUserLISTService() {
		return userLISTService;
	}
	public void setUserLISTService(IUserLISTService userLISTService) {
		this.userLISTService = userLISTService;
	}
	 

}
